package com.elitel.frame.main.config.serviceaccess.util;

import com.alibaba.fastjson.JSON;
import com.elitel.frame.main.entity.vo.JsonResult;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * PrintWriterUtil工具类
 * @author hi_bj
 */
public class ServiceAccessPrintWriterUtil {

    /**
     * 输出json 字符串
     * @param response HttpServletResponse
     * @param msg  消息内容
     * @throws IOException
     */
    public static void write(HttpServletResponse response, String msg) throws IOException {
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        JsonResult jr = new JsonResult();
        jr.setMsg(msg);
        jr.setSuccess(false);
        out.write(JSON.toJSONString(jr));
        out.flush();
        out.close();
    }
}
